const jwt = require('koa-jwt');
const Router = require('koa-router');
const router = new Router({ prefix: '/questions' });
const { secret } = require('../config');
const auth = jwt({ secret });
const {
  checkQuestionExist,
  checkQuestioner,
  find,
  findById,
  create,
  update,
  delete: del

} = require('../controllers/questions');

// 获取问题列表（可分页）（可查询关键字）
router.get('/', find);
// 创建问题
router.post('/', auth, create);
// 根据id获取问题
router.get('/:id', checkQuestionExist, findById);
// 根据id修改问题
router.patch('/:id', auth, checkQuestionExist, checkQuestioner, update);
router.delete('/:id', auth, checkQuestionExist, checkQuestioner, del);

module.exports = router;